from camel.agents import ChatAgent
from camel.models import ModelFactory
from camel.types import ModelPlatformType
from camel.messages import BaseMessage
from camel.types import RoleType
from camel.toolkits import SearchToolkit
from camel.toolkits import FunctionTool
from dotenv import load_dotenv
import os
load_dotenv()
Model_Type=os.getenv("MODEL_TYPE")
Model_Api=os.getenv("ZHIPU_API_KEY")
Model_Url=os.getenv("MODEL_URL")
model = ModelFactory.create(
    model_platform=ModelPlatformType.OPENAI,
    model_type=Model_Type,
    api_key=Model_Api,
    url=Model_Url
)
'''

def calculator(a:int, b:int) -> int:
    """
      执行两个数字的加减法运算

      Returns:
          int:两个数字的合
      """
    return a + b
def append(a:str, b:str) -> str:
    """
    用于拼接字符串，但用户会个性化增加内容

    return:
        str:两个字符串的拼接
    """
    return a + b
agent = ChatAgent(
    model=model,
    output_language="中文",
    tools=[calculator, append]
)
response =agent.step('what is 5 + 3?')
print(response.msgs[0].content)

#使用内置方法检查工具的属性
#转换为FunctionTool对象
calculator_tool = FunctionTool(calculator)
#获得工具名称
print(calculator_tool.get_function_name())
#获取描述
print(calculator_tool.get_function_description())
#获取所有字段
print(calculator_tool.get_openai_tool_schema())
print(calculator_tool.get_openai_tool_schema())
'''

# 工具包配置

# 创建SearchToolkit实例
search_toolkit = SearchToolkit()


# 获取搜索工具
tools = search_toolkit.get_tools()


# 创建聊天代理
agent = ChatAgent(
    model=model,
    output_language='中文',
    system_message="""你是一个专业的天气信息搜索助手""",
    tools=tools   #第一种
)
# agent.add_tools(tools)  #第二种

# 测试搜索功能
res = agent.step('明天郑州天气怎么样')
print("AI响应:", res.msgs[0].content)
